<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>
    <script>
        $(function () {
            $(".changeState").click(function () {
                var state = $(this).data("state")
                var id = $(this).data("id")
                $.get("/travel/changeState.do", {id: id, state: state}, function (data) {
                    if (data.success) {
                        window.location.reload();
                    }else {
                        $.messager.alert(data.msg)
                    }
                })
            })
            //淡出模态框并发送请求
            $(".checkContent").click(function () {
                var id = $(this).data("id")
                $.get("/travel/getContent.do", {id: id}, function (data) {
                    $(".modal-body").html(data.travelContent.content)
                    $("#contentModal").modal("show")
                })
            })

            //弹出模态框
            $(".commendBtn").click(function () {
                var id=$(this).data("id")
                var title=$(this).data("data")
                //清空表单框
                console.log(id);
                $("#inputModal").clearForm(true)
                //回显游记id
                $("#editForm input[name='travel.id']").val(id)
                $("#editForm input[name='title']").val(title)
                $("#inputModal").modal("show")
            })
            //点击保存按钮
            $(".saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.reload();
                    }else {
                        alert("失败")
                    }
                })
            })

        })
    </script>
    <style>
        #contentModal img{
            width: 100%;
        }
        #contentModal {
            max-height: 500px;  //最大高度
        overflow-y: auto;
        }
    </style>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="pass"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity.title!}</td>
                        <td><img src="${entity.coverUrl!}" width="30px"></td>
                        <td>${(entity.place.name)!}</td>
                        <td>${(entity.author.nickName)!}</td>
                        <td>${entity.releaseTime?string("yyyy-MM-dd")!}</td>
                        <td>${entity.stateName!}</td>
                        <td>
                            <a href="javaScript:;" class="checkContent" data-id="${entity.id}">查看文章</a>
                            <a href="javaScript:;" class="changeState" data-id="${entity.id}" data-state="2">取消发布</a>
                            <a href="javaScript:;" class="commendBtn" data-id="${entity.id}" data-data="${entity.title!}" >推荐</a>
                        </td>
                    </tr>
                </#list>
            </table>
           <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<!-- 内容显示（Modal） -->
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>
<!-- 推荐（Modal） -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    编辑
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/save.do" method="post" id="editForm" enctype="multipart/form-data" >
                    <input type="hidden" name="id">
                    <input type="hidden" name="travel.id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle"
                                   placeholder="请输入副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="50px" >
                            <input type="hidden" name="coverUrl">
                            <input type="file" class="form-control" name="pic">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()"
                                   placeholder="请输入副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">攻略推荐：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="1">周推荐</option>
                                <option value="2">月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary saveBtn">
                    <span class="glyphicon glyphicon-saved"></span> 提交更改
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>